package com.java.zhuiyun.api.sys_role.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.java.zhuiyun.api.sys_role.entity.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ClassName RoleMapper
 * @Description TODO
 * @Author xy
 * @Date 2023/8/16 15:44
 **/
@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    /**
     * @Author xy
     * @Description 全查
     * @Date 2023/8/15 18:49
     * @Return  * @param null
     */
    @Select("<script>select * from sys_role where del_flag = 0 <when test='roleName != null and roleName != &quot;&quot;'> " +
            "and role_name like concat('%', #{roleName}, '%') </when></script>")
    List<Role> RoleList(Role role);

    /**
     * @Author xy
     * @Description 添加
     * @Date 2023/8/15 20:10
     * @Return  * @param null
     */
    @Insert("insert into sys_role (role_name,description,flag,create_time,update_time) values " +
            "(#{roleName},#{description},#{flag},#{createTime},#{updateTime})")
    int RoleAdd(Role role);

    /**
     * @Author xy
     * @Description 逻辑删除
     * @Date 2023/8/15 16:41
     * @Return  * @param null
     */
    @Update("update sys_role set del_flag = 1 where id = #{id}")
    int RoleDelete(Integer id);

    @Select("select id from sys_role where flag = #{flag}")
    Integer selectByFlag(@Param("flag") String flag);

    @Update("update sys_role set role_name = #{roleName},description = #{description}," +
            "flag = #{flag},update_time = #{updateTime} where id = #{id}")
    int Roleupdate(Role role);
}
